﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using MySql.Data.MySqlClient;
using System.Data.OleDb;
using System.Web;
using System.Net;

namespace Cadastro
{
    public partial class Form1 : Form
    {
        PrincipalClass Prinn = new PrincipalClass();      
        
        public Form1()
        {
            InitializeComponent();
            CriaListaProfessor();
            CriaListaMataria();
            WebRequest request = WebRequest.Create("http://www.contoso.com/default.html");                                     
        }

        private void splitContainer1_Panel2_Paint(object sender, PaintEventArgs e)
        {

        }

        private void splitContainer1_Panel1_Paint(object sender, PaintEventArgs e)
        {

        }

        private void novoPlanoDeEnsinoToolStripMenuItem_Click(object sender, EventArgs e)
        {
            
        }

        private void gerenciarToolStripMenuItem_Click(object sender, EventArgs e)
        {
            CadastroMateria CadMat = new CadastroMateria();
            DataSet ds = new DataSet();
            DataRow row;
            row = CadMat.dsCad.Tables[0].NewRow();

            row[0] = Prinn.GetID("Materia", "idMateria");
            ds = Prinn.PesquisaGenerica("select * from professor").Tables[0].DataSet;

            //loop para preenchimento do combo box
            for (int cont = 0; cont < ds.Tables[0].Rows.Count; cont++)
            {
                CadMat.comboBox1.Items.Insert(cont,Convert.ToString(ds.Tables[0].Rows[cont][1]));
            }


            CadMat.dsCad.Tables[0].Rows.Add(row);
            CadMat.ShowDialog();
            CriaListaMataria();
        }

        private void tabPage1_Click(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            
                     

        }

        private void CriaListaProfessor()
        {
            DataSet ds = new DataSet();

            ds = Prinn.PesquisaGenerica("SELECT NOME FROM Professor");

            if (ds.Tables[0].Rows.Count != 0)
            {
                for (int cont = 0; cont < ds.Tables[0].Rows.Count; cont++)
                {
                    listView2.Items.Add(Convert.ToString(ds.Tables[0].Rows[cont][0]));
                }
            }
            else
            {
                listView2.Items.Add("Nao possui professor casatrado");
            }
        }

        private void CriaListaMataria()
        {
            DataSet ds = new DataSet();

            ds = Prinn.PesquisaGenerica("SELECT disciplina FROM materia");

            if (ds.Tables[0].Rows.Count != 0)
            {
                for (int cont = 0; cont < ds.Tables[0].Rows.Count; cont++)
                {
                    listView1.Items.Add(Convert.ToString(ds.Tables[0].Rows[cont][0]));
                }
            }
            else
            {
                listView1.Items.Add("Nao possui materia casatrado");
            }
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void novoProfessorToolStripMenuItem_Click(object sender, EventArgs e)
        {
            CadastroProfessor ProfCad = new CadastroProfessor();
            DataRow row;

            row = ProfCad.dsCad.Tables[0].NewRow();

            row[0] = Prinn.GetID("PROFESSOR", "IDProfessor");

            ProfCad.dsCad.Tables[0].Rows.Add(row);
            ProfCad.ShowDialog();
            CriaListaProfessor();
        }
       
    }
}
